HTML streaming

ABSTRACT

A method of speeding up the delivery of a dynamic webpage is disclosed. A request for a webpage is received, the webpage including one or more dynamic components. A cached stub is sent in response to the request, the cached stub including common components of the webpage that were empirically determined to be common components across multiple requests for the webpage. The request for the webpage is forwarded to an origin server. The webpage is received from the origin server. A difference between the cached stub and the webpage received from the origin server is determined. An instruction to correct the difference between the cached stub and the webpage received from the origin server is sent.

CROSS REFERENCE TO OTHER APPLICATIONS

This application claims priority to U.S. Provisional Patent Application No. 62/101,134 entitled HTML STREAMING filed Jan. 8, 2015 which is incorporated herein by reference for all purposes.

BACKGROUND OF THE INVENTION

Typically, an origin server generates a webpage by integrating static and dynamic content. The wait time experienced by an end-user of a browsing session may vary from a few hundred milliseconds to as much as several seconds. Therefore, improved techniques for delivering information corresponding to a webpage would be desirable.

BRIEF DESCRIPTION OF THE DRAWINGS

Various embodiments of the invention are disclosed in the following detailed description and the accompanying drawings.

FIG. 1 is a block diagram illustrating an embodiment of a web browser running a web application.

FIG. 2 is a diagram illustrating an embodiment of a webpage 200 described by an HTML file.

FIG. 3 is a diagram illustrating an embodiment of a DOM tree 300.

FIG. 4 illustrates that the DOM 402 may be accessed by a web application 404 and its scripts, and also by any legitimate third-party scripts, code or libraries (406).

FIG. 5 is a block diagram illustrating an embodiment of an optimized content delivery environment for efficiently delivering dynamic webpages (also referred to as HTML streaming).

FIG. 6 is a timing diagram illustrating an exemplary sequence of requests and responses sent and received by client device 502, proxy server 508, and origin server 510.

FIG. 7 is a flow diagram illustrating an embodiment of a process 700 for delivering a webpage with dynamic content.

FIG. 8 illustrates an embodiment of a process 800 after the proxy server receives a request for a webpage.

FIG. 9 illustrates an embodiment of a process 900 for learning a cached stub based on the received webpage from the origin server.

FIG. 10 illustrates an example of embedding a placeholder for a portion of a component and activating a virtualization client function to intercept and watch for any access to the placeholder.

FIG. 11 illustrates a DOM virtualization layer/client above DOM 402.

FIG. 12 illustrates an embodiment of a process 1200 for determining a new common set of components of a webpage that are safe to be included in the cacheable stub.

FIG. 13 illustrates an embodiment of a process 1300 for generating a cacheable stub for a webpage.

FIG. 14 illustrates an embodiment of a process 1400 for creating a set of commands to make corrections to the cached stub or to reload the webpage if the cached stub cannot be corrected safely.

FIG. 15 illustrates an example of determining a correction command for correcting a cached stub that has been served to a web browser.

FIG. 16 illustrates another example of determining a correction command for correcting a cached stub that has been served to a web browser.

DETAILED DESCRIPTION

The invention can be implemented in numerous ways, including as a process; an apparatus; a system; a composition of matter; a computer program product embodied on a computer readable storage medium; and/or a processor, such as a processor configured to execute instructions stored on and/or provided by a memory coupled to the processor. In this specification, these implementations, or any other form that the invention may take, may be referred to as techniques. In general, the order of the steps of disclosed processes may be altered within the scope of the invention. Unless stated otherwise, a component such as a processor or a memory described as being configured to perform a task may be implemented as a general component that is temporarily configured to perform the task at a given time or a specific component that is manufactured to perform the task. As used herein, the term ‘processor’ refers to one or more devices, circuits, and/or processing cores configured to process data, such as computer program instructions.

A detailed description of one or more embodiments of the invention is provided below along with accompanying figures that illustrate the principles of the invention. The invention is described in connection with such embodiments, but the invention is not limited to any embodiment. The scope of the invention is limited only by the claims and the invention encompasses numerous alternatives, modifications and equivalents. Numerous specific details are set forth in the following description in order to provide a thorough understanding of the invention. These details are provided for the purpose of example and the invention may be practiced according to the claims without some or all of these specific details. For the purpose of clarity, technical material that is known in the technical fields related to the invention has not been described in detail so that the invention is not unnecessarily obscured.

FIG. 1 is a block diagram illustrating an embodiment of a web browser running a web application. The web browser accesses webpages and other information through a network. As shown in FIG. 1, a web browser 102 is connected to a server 104 (e.g., an edge server) through a network 106. Network 106 may be any combination of public or private networks, including intranets, local area networks (LANs), wide area networks (WANs), radio access networks (RANs), Wi-Fi networks, the Internet, and the like. Web browser 102 may run on different types of devices, including laptop computers, desktop computers, tablet computers, smartphones, and other mobile devices.

A webpage accessed by web browser 102 may be described by different markup languages, including Hypertext Markup Language (HTML), Extensible Markup Language (XML), and the like. The webpage may be described by other custom languages as well. HTML is used hereinafter as an example of the various languages for describing webpages. Note that the examples of HTML are selected for illustration purposes only; accordingly, the present application is not limited to these specific examples.

FIG. 2 is a diagram illustrating an embodiment of a webpage 200 described by an HTML file. To display the webpage, web browser 102 sends a Hypertext Transfer Protocol (HTTP) request message to server 104 requesting the HTML webpage file. After server 104 locates the requested HTML webpage file, server 104 returns the requested HTML webpage file in an HTTP response message to web browser 102. As web browser 102 begins to render the webpage on a screen, web browser 102 parses the received webpage file and builds a data structure to represent the various components of the webpage in a local memory.

The Document Object Model (DOM) is a standardized model supported by different web browsers, e.g., Internet Explorer, Firefox, and Google Chrome, for representing the various components of a webpage. The DOM is a cross-platform and language-independent convention for representing and interacting with objects in HTML documents as well as XHTML and XML documents. Objects in a DOM tree may be addressed and manipulated using methods on the objects. The public interface of a DOM is specified in its application programming interfaces (APIs), known as the DOM APIs.

The DOM standard includes different levels. DOM core level 0 and level 1 are the core standards supported by all web browsers. DOM levels 2 and above are extensions to DOM core level 0 and level 1, which can be optionally supported by different web browsers. DOM core level 0 and level 1 define a minimal set of objects and interfaces for accessing and manipulating document objects. The DOM provides a complete model for an entire HTML document, including the means to change any portion of the document.

The DOM standard represents documents as a hierarchy of node objects, called a DOM tree. Within the document structure hierarchy, some types of nodes may have child nodes of various types, while other nodes are leaf nodes that cannot have any object below them.

FIG. 3 is a diagram illustrating an embodiment of a DOM tree 300. As shown in FIG. 3, the topmost node, or root, of DOM tree 300 is the document object. A document object represents an entire HTML (or XML) document, and it provides the primary access to the document's data. The element object represents an element in the HTML document. Other types of nodes in the DOM tree may include text nodes, anchors, text-boxes, text areas, radio buttons, check boxes, selects, buttons, and the like.

With continued reference to FIG. 2, when web browser 102 renders webpage 200 on a screen, web browser 102 parses the received HTML webpage file and builds a DOM tree to represent the various components of webpage 200 in a local memory. For example, when the image tag (shown as <img src=“url for image”/> in FIG. 2) is parsed by web browser 102, the image is represented as an image object, and the image object is accordingly inserted into the DOM tree.

After the webpage file is parsed and the corresponding DOM tree is created, the entire DOM tree can be traversed to retrieve any dependent resources (e.g., images, JavaScripts, audio clips, or videos) indicated by any of the nodes in the DOM tree via a network. For example, the image object corresponding to the image tag in webpage 200 redirects web browser 102 to fetch an image file from an uniform resource locator (URL). Accordingly, web browser 102 sends a request via a network, requesting the image resource to be downloaded. There are two ways a request may be issued: statically, in which case it is the browser which manipulates the DOM; or dynamically, in which case the DOM manipulation is done by JavaScript. In response to the request, the requested dependent resource is sent to web browser 102 via a network.

A web application may include scripts that are executed when different DOM events occur. DOM event APIs allow event-driven programming languages (e.g., JavaScript, Jscript, ECMAScript, VBScript, and Java) to register various DOM event handlers/listeners with the element nodes inside a DOM tree. Different types of events can be generated by the element nodes inside a DOM tree, including mouse events, keyboard events, HTML frame/object events, HTML form events, user interface events, mutation events, progress events, and the like. For example, the DOM event API “onclick” is triggered when a user clicks on an element, and a script that has registered as a callback script for the “onclick” event will be executed. In another example, the DOM event APIs “onKeyDown” and “onKeyup” are triggered when a user presses a key and releases a key, respectively. In another example, the DOM event API “oninput” is triggered when an element receives user inputs.

FIG. 4 illustrates that the DOM 402 may be accessed by a web application 404 and its scripts, and also by any legitimate third-party scripts, code or libraries (406).

With continued reference to FIGS. 1 and 2, since the network latency associated with different types of networks varies widely, and web browser 102 needs to receive webpage 200 and its dependent resources before web browser 102 can complete the rendering of webpage 200, the startup wait time experienced by the end-user of the browsing session may be insignificant in low-latency networks, such as Wi-Fi or cable networks, but unacceptably long for an end-user in higher-latency networks, such as 3G networks. Traditionally, by caching content such as webpages or webpage components close to a requestor of the content, the content can be quickly retrieved from the cache rather than the origin server, saving bandwidth and time. However, caching is of limited value when the requested content is dynamic. Once the cached content has been changed, the cached content must be discarded and the updated content must be retrieved from the origin server again. As a result, when at least a portion of the content in a webpage is dynamic, the webpage is typically treated as non-cacheable, and therefore needs to be regenerated repeatedly by the origin server.

The processing time for regenerating a dynamic webpage can be long, leading to long latencies and lowered responsiveness of the website perceived by the user. For example, an origin server may be blocked by database queries to retrieve information required to generate the dynamic webpage. The processing time is dependent on the type or the amount of the information retrieved. For example, the processing time may be minimal for a simple name lookup, but long if a large block of data is fetched. Therefore, the processing time may vary from a few hundred milliseconds to several seconds. During this processing time, the web browser is idling and waiting for the HTTP response to its HTTP request, and the web browser is blocked from downloading any resources. Therefore, improved techniques for delivering information are desirable.

Although a dynamic webpage file may be dynamic and uncacheable as a whole, the webpage may include both static components and dynamic components that change over time. Static components in a dynamic page may include shared non-unique components, such as company logos and images, that stay unchanged across multiple requests sent to the origin server. Dynamic components in a dynamic webpage may include components that change over time, including news, weather forecasts, market data, and the like. Dynamic components in a dynamic webpage may also include components that are unique, customized, or personalized. A dynamic webpage may be a webpage that is generated and customized on a per-user or per-group basis. For example, when a user logs onto a social networking website (e.g., Facebook) or an online merchant website (e.g., Amazon.com), the website generates a dynamic webpage that includes static components as well as components that are in part based on the user's identity or the user's preferences and are therefore unique for each user.

FIG. 5 is a block diagram illustrating an embodiment of an optimized content delivery environment for efficiently delivering dynamic webpages (also referred to as HTML streaming). Block diagram 500 illustrates a client device 502, a proxy server 508, and an origin server 510 communicating across networks 512. Networks 512 may be any combination of public or private networks, including intranets; local area networks (LANs), wide area networks (WANs), radio access networks (RANs), Wi-Fi networks, the Internet, and the like. In some embodiments, proxy server 508 is a server that belongs to a content delivery network or content distribution network (CDN). Client device 502 includes a web browser 504 and a virtualization client 506. Examples of client device 502 include laptop computers, desktop computers, tablet computers, smartphones, and other mobile devices. FIG. 6 is a timing diagram illustrating an exemplary sequence of requests and responses sent and received by client device 502, proxy server 508, and origin server 510. FIG. 7 is a flow diagram illustrating an embodiment of a process 700 for delivering a webpage with dynamic content. In some embodiments, process 700 is a process running on proxy server 508 in FIG. 5.

With reference to FIGS. 5-7, at time t₁, web browser 504 running on client device 502 sends an HTTP request message requesting an HTML webpage. At time t₂ and step 702, proxy server 508 receives the HTTP request message. At step 704, after receiving the HTTP request message, proxy server 508 forwards the HTTP request message to origin server 510, querying origin server 510 for the latest version of the HTML webpage, and waits for the HTML webpage in an HTTP response message, which is expected to be sent by origin server 510 in response to the HTTP request message.

Step 706 may be performed in parallel with step 704. At step 706, without waiting for the arrival of the HTTP response message from origin server 510, proxy server 508 sends a temporary webpage (hereinafter referred to as the fast-delivery webpage) based on profiling information corresponding to the requested webpage to web browser 504. The fast-delivery webpage is a “safe,” cacheable “stub” that was previously generated and cached by proxy server 508. The cached stub includes cacheable components, e.g., static and shared non-unique components, of the HTML webpage. Components include script components or other elements, such as meta elements and link elements. The cached stub generated by proxy server 508 includes information and resources that proxy server 508 predicts web browser 504 would actually receive or need to further download had the actual webpage been sent by origin server 510 and received by web browser 504. The cached stub also enables the injection of virtualization client 506 onto client device 502. Virtualization client 506 (also referred to as a nanovisor) includes a DOM virtualization layer added on top of the DOM. Virtualization of a DOM of a web browser allows virtualization client 506 and proxy server 508 to take control of the DOM for different kinds of optimizations, while keeping the virtualization transparent to the web browser. In some embodiments, virtualization client 506 may be injected into web browser 504 based on standards-based (e.g., HTML or JavaScript) procedures. For example, virtualization client 506 may be injected by adding JavaScript client code (e.g., <script src=“nanovisor.js”></script>) in the head section of the cached stub webpage.

At time t₃, web browser 504 receives the cached stub from proxy server 508. Virtualization client 506 initializes and starts to run on client device 502. Web browser 504 no longer needs to stay idle, but is unblocked from handling different tasks. For example, web browser 504 may begin to process any information included in the cached stub or to load some of the information onto memory, or may begin to initiate further downloading of dependent resources, including images, videos, audio clips, and the like.

Proxy server 508 continues to wait for the actual HTML webpage in an HTTP response message, which is expected to be sent by origin server 510 in response to the HTTP request message. At time t₄, origin server 510 receives the HTTP request message forwarded by proxy server 508. In response to the HTTP request message, origin server 510 processes the request message and generates the HTTP response message including the most updated HTML webpage and sends the HTTP response message to proxy server 508. At time t₅ and step 708, proxy server 508 intercepts the HTTP response message.

Proxy server 508 scans and processes the received webpage from origin server 510. At step 710, proxy server 508 compares the received webpage with the cached stub that has already been sent by proxy server 508 to web browser 504 to determine the differences between the two versions. At step 712, proxy server 508 determines whether the differences between the two versions can be patched/corrected safely, i.e., without any side effects or errors. At step 714, if the differences can be corrected safely, then proxy server 508 creates a set of correction/patch commands (e.g., JavaScript commands) that can be run by virtualization client 506 to correct the differences. For example, the set of commands may delete or modify the components that were previously included in the cached stub webpage. The set of commands may also add new components in the updated webpage that were not included in the cached stub webpage. At step 716, in the event that the differences cannot be corrected safely, proxy server 508 creates a set of commands that can be run by virtualization client 506 to direct web browser 504 to reload the HTML webpage. At step 718, the received webpage is used to automatically learn the cached stub corresponding to the received webpage.

At time t₆, proxy server 508 completes the response to web browser 504 by sending the commands and any additional information to web browser 504, such that web browser 504 may complete the rendering of the actual HTML webpage. At time t₇, virtualization client 506 intercepts the commands and information and executes the set of commands. By time t₈, either the differences between the cached stub webpage and the most updated version of the HTML webpage are corrected safely or the HTML webpage is reloaded if the differences cannot be corrected safely without any side effects or errors.

As shown in FIG. 6, using HTML streaming techniques, if a cached stub webpage is cached at proxy server 508 and sent to web browser 504, web browser 504 is unblocked at time t′₁ and may begin to process any information included in the cached stub webpage or load some of the information onto memory, or begin to initiate any further downloading of dependent resources, including images, videos, audio clips, and the like. The above described techniques enable more efficient use of both bandwidth and computing resources by reducing the idling time within which bandwidth and computing resources are unutilized. Without HTML streaming, the HTTP request message would have went all the way to origin server 510 and the HTTP response message would have arrived at web browser 504 at time t′₂, as shown by the dashed path on FIG. 6. The time difference (t′₂−t′₁) is the reduced idling time of web browser 504 due to HTML streaming. The time difference allows web browser 504 a head-start in the rendering of the HTML webpage.

FIG. 8 illustrates an embodiment of a process 800 after the proxy server receives a request for a webpage. In some embodiments, process 800 is a process performed at steps 704 and 706 of process 700 in FIG. 7.

At step 802, after receiving the HTTP request message requesting a webpage, proxy server 508 looks up a cached stub for the requested webpage in a cache. At step 804, if there is a cache hit; then at step 806, the cached stub corresponding to the requested webpage is sent to web browser 504 as the cached stub webpage. Virtualization client 506 is injected by adding JavaScript client code (e.g., <script src=“nanovisor.js”></script>) in the head section of the cached stub webpage. At step 808, proxy server 508 forwards the HTTP request message to origin server 510, querying origin server 510 for the latest version of the HTML webpage. At step 804, if there is not a cache hit, then process 800 proceeds to step 808 and proxy server 508 forwards the HTTP request message to origin server 510, querying origin server 510 for the latest version of the HTML webpage.

In some embodiments, chunked transfer encoding is used to deliver the cached stub webpage sent at step 806 of process 800 first and then subsequently any updated or additional information extracted from the updated webpage from origin server 510. Chunked transfer encoding is a data transfer mechanism in version 1.1 of HTTP wherein data is sent in a series of “chunks”. The mechanism uses the Transfer-Encoding HTTP header in place of the Content-Length header, which the protocol would otherwise require. Because the Content-Length header is not used, the sender does not need to know the length of the content before it starts transmitting a response to the receiver; senders can begin transmitting dynamically-generated content before knowing the total size of that content. The size of each chunk is sent right before the chunk itself, so that the receiver can tell when it has finished receiving data for that chunk. The data transfer is terminated by a final chunk of length zero.

For example, proxy server 508 may use chunked transfer encoding to send the cached stub corresponding to the requested webpage in a series of one or more initial “chunks” to web browser 504. Any updated or additional information and any commands to correct the differences between the sent version and the updated version of the webpage may be sent to web browser 504 in a series of subsequent “chunks.” When all the updated information and commands have been sent, the data transfer is terminated by a final chunk of length zero. For example, proxy server 508 may send an initial “chunk” that includes the head section and the <body> tag of the HTML webpage file. The head section includes the cached stub, which includes the cacheable components, e.g., static and shared non-unique components, of the HTML webpage. The head section also includes the injected virtualization client code. After the updated webpage file is received from origin server 510, proxy server 508 may send a subsequent “chunk” (or subsequent “chunks”) that includes the actual content of the body section, any updated information and any correction commands, followed by the </body> and </html> tags.

The cached stub of a webpage should include components that are empirically determined to be safe to be served to web browser 504 ahead of time. One way to guarantee that the cached stub is safe is to work with the content provider. The content provider may identify the static components. The content provider may also move the dynamic components out of the head section. However, this method is cumbersome and non-scalable.

In some embodiments, the cached stub is automatically and empirically learned by the system. For any HTML webpage, a cached stub is learned during a learning period. In some embodiments, the learning is a continuous process that repeats after a predetermined period of time. In some embodiments, the learning is a continuous process that repeats after a predetermined number of webpage requests/responses have been sent/received. During a learning period, proxy server 508 observes which components in the webpage remain common across multiple requests, and which components are changing and how. In some embodiments, proxy server 508 observes the common components in the head section of the webpage only: only static common components in the head section are included in the cached stub and sent to web browser 504 ahead of time. In some embodiments, proxy server 508 may observe the common components in the body section as well. In the latter case, the computational overhead is higher, but more static common components in the webpage may be delivered ahead of time. At the end of the learning period, the stub is learned and it can be stored in the cache, replacing an older version of the stub learned in the previous learning period.

FIG. 9 illustrates an embodiment of a process 900 for learning a cached stub based on the received webpage from the origin server. In some embodiments, process 900 is a process performed during step 718 of process 700 in FIG. 7.

At step 902, it is determined whether the received webpage is the first one received within the current learning period. At step 904, if the received webpage is the first one, then the components in the received webpage are used to initialize a data structure named CommonNodes. The data structure CommonNodes stores the common static components of the webpage found within a learning period thus far. Process 900 then proceeds to step 906. If the received webpage is not the first one received within the current learning period, then process 900 proceeds to step 906.

At step 906, a new set of common static components of the webpage found within the current learning period is determined. New_(CN) is the data structure used to store the new set of common static components of the webpage within the current learning period. Although a new set of common components is now available, New_(CN) is only used to update the cached stub when one of two criteria is satisfied. One criterion is that the learning period is complete and that the previous cached stub has expired. At step 908, it is determined whether the learning period is complete. If the learning period is complete at step 910, then a new cacheable stub for the webpage is generated. At step 914, a new learning period is restarted. The data structure CommonNodes is reset to empty. At step 916, the generated cacheable stub obtained at step 910 is stored into the cache.

A second criterion is that the data structure CommonNodes becomes unstable. CommonNodes is unstable when the new set of common static components (New_(CN)) is smaller in size (number of components) than the size of CommonNodes. At step 912, it is determined whether the data structure CommonNodes becomes unstable. If it is true, at step 918, the new set of common static components (New_(CN)) is saved into the data structure CommonNodes, replacing its previous contents. At step 920, a new cacheable stub for the webpage is generated. At step 922, the generated cacheable stub obtained at step 910 is stored into the cache.

As mentioned above, the cached stub of a webpage should include components that are safe to be served to web browser 504 ahead of time. The stub should not include any user-specific information. For example, Meta data in the head section may include user-specific information, such as a username. Such information should be excluded from the cached stub because user-specific information should not be sent to other users. Stale versions of any changing component should be excluded from the cached stub.

In some situations, a script in a webpage that remains common across multiple requests may still be unsafe to be pre-executed by the web browser and is therefore excluded from the cached stub. A script can change the underlying DOM as the script is being executed. Changing the DOM may in turn impact the execution of other subsequent scripts. Therefore, if a script is not common across requests, then all subsequent scripts in the same webpage are removed from the stub.

For example, suppose one instance of a webpage has four JavaScripts, JS1, JS2, JS3, and JS4, while other instances of the same webpage have only three scripts, JS1, JS3, and JS4. Since the changing script JS2 may change the underlying DOM, and JS3 and JS4 may have dependencies upon those changes, JS3 and JS4 must be excluded from the cached stub even if JS3 and JS4 are consistently found on all instances of the webpage.

In some situations, a component of a webpage may not be completely identical across multiple requests but it is sufficiently similar across multiple requests that it can be included into the cached stub. For example, a component of a webpage may have the same number and types of attributes across multiple requests but the value of one of the attributes may change over time. If such a component were to be included in the cached stub, then the component would need to be monitored by the system to ensure that the changing portion of the component can be corrected safely, without causing any errors or side-effects. In some embodiments, the component is monitored by the system by embedding a “placeholder” for the possibly changing portion of the component and activating a function of the virtualization client (also referred to as a nanovisor) to intercept and watch for any access to the placeholder. If the watched portion of the component of the most recently received webpage has indeed changed, and the intercepting function has previously intercepted at least one access to the placeholder (e.g., by a cached script), then it is determined that the change cannot be safely corrected and that a reloading of the webpage by the virtualization client is required to ensure that the webpage is re-created correctly. The goal is that any corrections should be completely transparent. Once all the corrections are performed by the correcting commands, the resulting webpage should be exactly as if it was fetched directly from origin server 510.

FIG. 10 illustrates an example of embedding a placeholder for a portion of a component and activating a virtualization client function to intercept and watch for any access to the placeholder. Within a single learning period, two instances of the same webpage (webpage 1002 and webpage 1004) are received. Webpage 1002 is received by proxy server 508 in response to a request R1. Webpage 1004 is received by proxy server 508 in response to a request R2 As shown in webpage 1002 and webpage 1004, the link element stays unchanged but the value of attribute b of the meta element changes from “x” to “z.” After the learning period is over, a cached stub 1006 is stored in the cache. The link element is stored in the cached stub 1006 without a placeholder. The meta element is also included in the cached stub 1006, but the changing attribute value is removed and a placeholder for the value of attribute b is added. The placeholder in this example is an empty string. In addition, a virtualization client function InterceptNode( ) is invoked to intercept and watch for any access to the placeholder by a script. If an access to the placeholder by a script is intercepted, then a reloading of the webpage is triggered.

The virtualization client is able to intercept and watch for any access to the placeholder on the client side because the virtualization client is a DOM virtualization layer/client added on top of the DOM. FIG. 11 illustrates a DOM virtualization layer/client above DOM 402. Virtualization client 1102 may intercept the DOM APIs that pass information or instructions between the DOM 402 and different types of scripts. Virtualization client 1102 may supplant an intercepted DOM API with a new DOM API. For example, the new DOM API may selectively block the intercepted DOM API based on different criteria. The new DOM API may also modify the intercepted DOM API and pass a modified version of the intercepted DOM API to the DOM or the caller/user. The new DOM API may also trigger an alert in response to an intercepted DOM API.

FIG. 12 illustrates an embodiment of a process 1200 for determining a new common set of components of a webpage that are safe to be included in the cacheable stub. In some embodiments, process 1200 is a process (ComputeCommon) performed during step 906 of process 900 in FIG. 9.

At step 1202, New_(CN) is reset to empty. JS_Mod is a flag that is set to true if a script in the webpage is found to be non-common across multiple requests. JS_Mod is initialized to false at step 1202. Next, each of the components in the received webpage is processed in a loop. The top of the loop is shown as “A” in process 1200. At step 1204, it is determined whether there is another component (n) in the received webpage to process. If there is an additional component, then process 1200 proceeds to step 1206; otherwise, process 1200 terminates.

At step 1206, it is determined whether this component n is an exact match with another node in CommonNodes. If it is an exact match, process 1200 proceeds to step 1208. At step 1208, it is determined if the exactly matched component n is not a script or if JS_Mod has not been set. If the result at 1208 is false, then the component is not saved and the process returns back to the top of the loop (A) to process additional components, if any. In this case, the component is not saved because it is a script that follows another script that has been modified or deleted. If the exactly matched component n is not a script, then process 1200 proceeds to step 1210. If the exactly matched component n is a script, but JS_Mod is false, then process 1200 also proceeds to step 1210. At step 1210, the component is added to New_(CN) and marked as “Common,” indicating that the exactly matched component n is saved as a common node “as is.” After step 1210, process 1200 returns back to the top of the loop (A) to process additional components, if any.

At step 1206, if component n is not an exact match with another node in CommonNodes, then process 1200 proceeds to step 1212. At step 1212, it is determined whether component n is a script. If component n is a script, then JS_Mod is set to true at step 1214. After step 1214, process 1200 returns back to the top of the loop (A) to process additional components, if any. If component n is not a script, then process 1200 proceeds to step 1216.

At step 1216, it is determined whether component n has the same set of attributes as one node c in CommonNodes. It is further determined whether the component n has the attributes “id,” “name,” and “type” having the same values as those in node c. If the above conditions are met, then process 1200 proceeds to step 1218. At step 1218, the component n is added to New_(CN) and the component is marked as “Changing,” indicating that the component n is saved as a common node but it has at least an attribute that changes its value over time. A placeholder will later be added to the component if it is marked as “Changing.” After step 1218, process 1200 returns back to the top of the loop (A) to process additional components, if any.

FIG. 13 illustrates an embodiment of a process 1300 for generating a cacheable stub for a webpage. In some embodiments, process 1300 is a process (GenerateStub) performed during step 910 or step 920 of process 900 in FIG. 9.

In process 1300, first, each of the nodes in the new set of common nodes is processed in a loop. The top of the loop is shown as “B” in process 1300. At step 1302, it is determined whether there is another node in the new set of common nodes to process. If there is an additional node, then process 1300 proceeds to step 1304; otherwise, process 1300 proceeds to step 1312.

At step 1304, it is determined whether this node n is marked as “Common.” If it is marked as “Common,” then the contents of n are appended to the stub at step 1306. Process 1300 then returns back to the top of the loop (B) to process additional nodes, if any. Otherwise, at 1308, it is determined if the node is marked as “Changing.” If false, process 1300 returns back to the top of the loop (B) to process additional nodes, if any. If true at step 1310, a placeholder is created with the same attributes as n and all the attribute values are set to empty. The placeholder is added to the stub. In addition, a script node is added to invoke a nanovisor function to intercept all accesses to the placeholder. After step 1310, process 1300 returns back to the top of the loop (B) to process additional nodes, if any.

At step 1312, all nodes in the new set of common nodes have been processed. For each entry in the stub, the patch_id of the entry is set to its current position in the stub. After step 1312, the stub is returned and the process is complete.

FIG. 14 illustrates an embodiment of a process 1400 for creating a set of patch/correction commands to make corrections to the cached stub or to reload the webpage if the cached stub cannot be corrected safely. In some embodiments, process 1400 is a process (Create_Patch_Cmds_Or_Reload) performed during steps 710, 712, 714, and 716 of process 700 in FIG. 7.

In process 1400, first, each of the components in the received webpage is processed in a FOR loop (see 1402). For each component i, it is determined whether the component exists in the cached stub. If the component exists in the stub, then the matching component in the stub is marked as “matched” and the next component is processed. Otherwise, it is determined whether the component has a placeholder. For example, it is determined whether the component has a placeholder component in the stub with the same type, the same set of attributes, and located at the same position i within the stub as the component is located within the received webpage. If there is such a placeholder component in the stub, then a patch/correction command is appended to Pc, a data structure that stores the correction commands to be sent to the client side. The placeholder is then replaced by the updated received value. If there is not such a placeholder, it is determined if there is a script element in the stub at position ‘i’ or after position ‘i’. If such a script element exists, then it is unsafe to patch the current component and the flag reload is set to true (scenario 1404); it is unsafe to insert a new component before a script because the script might have already tried to access the component. If there is not a script element in the stub after position ‘i’, then a patch/correction command is created to be sent to the web browser (scenario 1406).

At 1408, all the components in the received webpage have been processed by the FOR loop, and it is determined whether there is a component in the stub that has yet to be matched. If there is a script in the stub after the unmatched component in the stub, then the flag reload is set to true. It is unsafe to delete this component from the stub because a script that follows it might have already tried to access the missing component. Therefore, the webpage should be reloaded. If there is no script in the stub after the unmatched component in the stub, then a “delete” patch command is appended to Pc to be sent to the client side.

At 1410, if the flag reload is true, then the contents of Pc are replaced with a reload patch command. After 1410, the patch commands in Pc are sent to the client side.

FIG. 15 illustrates an example of determining a correction command for correcting a cached stub that has been served to a web browser.

As shown in FIG. 15, a stub 1502 for a webpage was sent by proxy server 508 to web browser 504 in response to a webpage request. Cached stub 1502 includes a meta element and a link element. The meta element was assigned a patch_id=0 and the link element was assigned a patch_id=1. The patch_id is used to identify the position of a component within the cached stub.

An updated webpage 1504 is later received from origin server 510 by proxy server 508. Updated webpage 1504 includes two meta elements and one link element. The second meta element in updated webpage 1504 is new and therefore was not included in the stub previously sent to web browser 504. Since the new meta element is not followed by any script element, it is safe for proxy server 508 to instruct virtualization client 506 to insert the new meta element into the DOM. Accordingly, an “INSERT” patch command 1506 is sent to the client side, which is handled by scenario 1406 of process 1400 in FIG. 14. Patch command 1506 invokes virtualization client 506 to insert the new meta element into the DOM before patch_id=1 (i.e., after the first meta element (patch_id=0) but before the link element (patch_id=1)). Virtualization client 506 may then use a DOM API to insert the new meta element into the correct position in the DOM tree.

FIG. 16 illustrates another example of determining a correction command for correcting a cached stub that has been served to a web browser.

As shown in FIG. 16, a stub 1602 for a webpage was sent by proxy server 508 to web browser 504 in response to a webpage request. Cached stub 1602 includes a meta element, a link element, and a script element. The meta element was assigned a patch_id=0, the link element was assigned a patch_id=1, and the script element was assigned a patch_id=2. The patch_id is used to identify the position of a component within the cached stub.

An updated webpage 1604 is later received from origin server 510 by proxy server 508. Updated webpage 1604 includes two meta elements, one link element, and one script element. The second meta element in updated webpage 1604 is new and therefore was not included in the stub previously sent to web browser 504. Since the new meta element is followed by a script element, it is unsafe for proxy server 508 to instruct virtualization client 506 to insert the new meta element into the DOM. Accordingly, a “Reload” patch command 1606 is sent to the client side, which is handled by scenario 1404 of process 1400 in FIG. 14. Patch command 1606 invokes virtualization client 506 to cause a reload of the webpage.

The duration of the learning period for learning a cached stub of a webpage is a parameter that can be fine-tuned for increased performance. A longer learning period allows the proxy server to observe many different instances of the same webpage sent in response to different requests that are sent under different conditions, e.g., from different users, from different geographic locations, and at different times. When the learning period captures sufficient request diversity, the proxy server may more accurately include the cacheable components in the cached stub and exclude the non-cacheable components from the cached stub. However, the tradeoff of having a longer learning period is that the system will be less agile in adapting to any changes of the webpage made by the publisher/origin server.

On the other hand, if the learning period is too short, the learned cached stub may be unsafe, which may lead to frequent reloading of the webpage. Unfortunately, it may not be possible to determine a minimum threshold for the learning period in advance. To illustrate this point further, consider an origin server that has two versions of the same webpage—version one being served to 5% of the users and version two being served to the remaining 95% of the users. Statistically speaking, in order to avoid creating a stub before the proxy server has a chance to observe the responses sent to the 5% of the users, i.e., those requesting version one of the webpage, the learning period should be long enough to observe at least 100/5=20 responses. Since the percentage breakdown of the different versions of any given webpage is not known a priori, a minimum threshold for the learning period cannot be determined in advance by the proxy server.

Furthermore, a webpage may also go through certain phases during which a cached stub cannot be constructed safely. During these phases, a cached stub should not be served to the web browser ahead of time: HTML streaming should be switched off for a period of time and relearning attempted at a later time, when a cached stub can be more safely constructed. Therefore, improved techniques for adaptively adjusting the duration of the learning period for learning a cached stub of a webpage are desirable.

In some embodiments, the duration of the learning period for learning a cached stub of a webpage is dynamically adapted. The proxy server may monitor the frequency of occurrence of reloading of the webpage. For example, within a window measured by a number of requests most recently observed, the proxy server determines the percentage of requests within the window resulting in a reloading of the webpage and the reasons why the webpage was reloaded. If the reloading of the webpage was triggered by the client side (i.e., the reloading is triggered when the nanovisor watch function has intercepted an illegal access of a placeholder component in a stub), then the reloading cannot be reduced by increasing the learning period. Conversely, if the reloading of the webpage was triggered by the proxy server, then the reloading may be caused by a learning period that is too short to capture sufficient request diversity, and thus the reloading can be reduced by increasing the learning period.

Accordingly, if the percentage/frequency of requests resulting in a reloading of the webpage triggered by the client side exceeds a predetermined threshold, then HTML streaming is switched off for a period of time such that a cached stub is no longer sent in advance to the web browser. The relearning may be attempted at a later time when a cached stub can be constructed more safely. If the percentage of requests resulting in a reloading of the webpage triggered by the proxy server exceeds a predetermined threshold, then the cached stub is reset and HTML streaming is disabled. Learning is restarted with a longer learning period (e.g., by scaling the previous learning period by a factor). Increasing the learning period enhances the possibility of capturing the diversity of user requests and creating a safe, reload-free stub. The scaling of the learning period by an increasing factor is repeated until the percentage of requests resulting in a reloading of the webpage falls below the predetermined threshold. For example, the learning period may be scaled by a factor of 2, 4, 8, and so forth until the reloading percentage drops below the predetermined threshold or the cache TTL is reached. At this point, the learning period may be reset back to the default duration again.

Dynamically adapting the learning period as described above has many advantages. The learning period can be automatically optimized for different webpages and automatically adjusted based on the frequency at which updates of a webpage is applied. The learning process becomes more agile, thereby increasing the effectiveness of the entire system. Furthermore, without the need for manual configurations, the system becomes more scalable.

Although the foregoing embodiments have been described in some detail for purposes of clarity of understanding, the invention is not limited to the details provided. There are many alternative ways of implementing the invention. The disclosed embodiments are illustrative and not restrictive. 

What is claimed is:
 1. A method of speeding up the delivery of a dynamic webpage, comprising: receiving a request for a webpage, the webpage including one or more dynamic components; sending a cached stub in response to the request, the cached stub including common components of the webpage that were empirically determined to be common components across multiple requests for the webpage; forwarding the request for the webpage to an origin server; receiving the webpage from the origin server; determining a difference between the cached stub and the webpage received from the origin server; and sending an instruction to correct the difference between the cached stub and the webpage received from the origin server.
 2. The method of claim 1, wherein empirically determining the common components of the webpage comprises excluding user-specific information from the common components.
 3. The method of claim 1, further comprising: excluding a first script component from being included in the cached stub, wherein the first script component was empirically determined to be common across multiple requests for the webpage, and wherein the first script component is preceded by a second script component that was empirically determined to be uncommon across multiple requests for the webpage.
 4. The method of claim 1, further comprising: determining that the webpage received from the origin server includes a new component inserted in the webpage, wherein the new component was not included in the cached stub; determining that inserting the new component in the cached stub would have resulted in the new component being inserted before at least one script component in the cached stub; and configuring the instruction to cause a reloading of the webpage.
 5. The method of claim 1, further comprising: determining that the webpage received from the origin server includes a new component inserted at a position in the webpage, wherein the new component was not included in the cached stub; determining that inserting the new component in the cached stub would not have resulted in the new component being inserted before at least one script component in the cached stub; and configuring the instruction to insert the new component into a DOM tree based on the position of the new component in the webpage.
 6. The method of claim 1, comprising: determining that a component included in the cached stub has been deleted from the webpage received from the origin server; determining that there is a script component in the cached stub following the deleted component; and configuring the instruction to cause a reloading of the webpage.
 7. The method of claim 1, comprising: determining that a component included in the cached stub has been deleted from the webpage received from the origin server; determining that there is not a script component in the cached stub following the deleted component; and configuring the instruction to delete the component from the DOM tree.
 8. The method of claim 1, wherein empirically determining the common components of the webpage comprises empirically determining common components of the webpage within a head section of the webpage.
 9. The method of claim 1, further comprising: including a component in the cached stub, wherein the component was empirically determined to be similar but not identical across multiple requests for the webpage, wherein the component was empirically determined as having the same number and the same types of attributes across multiple requests for the webpage but having at least one attribute with a value that changes across multiple requests for the webpage; and replacing the at least one attribute of the component included in the cached stub by a placeholder; and activating a script that intercepts any access to the placeholder, wherein the script causes a reloading of the webpage in response to a determination that the placeholder has been accessed.
 10. A system for speeding up the delivery of a dynamic webpage, comprising: a processor configured to: receive a request for a webpage, the webpage including one or more dynamic components; send a cached stub in response to the request, the cached stub including common components of the webpage that were empirically determined to be common components across multiple requests for the webpage; forward the request for the webpage to an origin server; receive the webpage from the origin server; determine a difference between the cached stub and the webpage received from the origin server; and send an instruction to correct the difference between the cached stub and the webpage received from the origin server; and a memory coupled to the processor and configured to provide the processor with instructions.
 11. The system of claim 10, wherein empirically determining the common components of the webpage comprises excluding user-specific information from the common components.
 12. The system of claim 10, wherein the processor is further configured to: exclude a first script component from being included in the cached stub, wherein the first script component was empirically determined to be common across multiple requests for the webpage, and wherein the first script component is preceded by a second script component that was empirically determined to be uncommon across multiple requests for the webpage.
 13. The system of claim 10, wherein the processor is further configured to: determine that the webpage received from the origin server includes a new component inserted in the webpage, wherein the new component was not included in the cached stub; determine that inserting the new component in the cached stub would have resulted in the new component being inserted before at least one script component in the cached stub; and configure the instruction to cause a reloading of the webpage.
 14. The system of claim 10, wherein the processor is further configured to: determine that the webpage received from the origin server includes a new component inserted at a position in the webpage, wherein the new component was not included in the cached stub; determine that inserting the new component in the cached stub would not have resulted in the new component being inserted before at least one script component in the cached stub; and configure the instruction to insert the new component into a DOM tree based on the position of the new component in the webpage.
 15. The system of claim 10, wherein the processor is further configured to: determine that a component included in the cached stub has been deleted from the webpage received from the origin server; determine that there is a script component in the cached stub following the deleted component; and configure the instruction to cause a reloading of the webpage.
 16. The system of claim 10, wherein the processor is further configured to: determine that a component included in the cached stub has been deleted from the webpage received from the origin server; determine that there is not a script component in the cached stub following the deleted component; and configure the instruction to delete the component from the DOM tree.
 17. The system of claim 10, wherein empirically determining the common components of the webpage comprises empirically determining common components of the webpage within a head section of the webpage.
 18. The system of claim 10, wherein the processor is further configured to: include a component in the cached stub, wherein the component was empirically determined to be similar but not identical across multiple requests for the webpage, wherein the component was empirically determined as having the same number and the same types of attributes across multiple requests for the webpage but having at least one attribute with a value that changes across multiple requests for the webpage; and replace the at least one attribute of the component included in the cached stub by a placeholder; and activate a script that intercepts any access to the placeholder, wherein the script causes a reloading of the webpage in response to a determination that the placeholder has been accessed.
 19. A computer program product for speeding up the delivery of a dynamic webpage, the computer program product being embodied in a non-transitory computer readable storage medium and comprising computer instructions for: receiving a request for a webpage, the webpage including one or more dynamic components; sending a cached stub in response to the request, the cached stub including common Components of the webpage that were empirically determined to be common components across multiple requests for the webpage; forwarding the request for the webpage to an origin server; receiving the webpage from the origin server; determining a difference between the cached stub and the webpage received from the origin server; and sending an instruction to correct the difference between the cached stub and the webpage received from the origin server.
 20. The computer program product recited in claim 19, further comprising computer instructions for: including a component in the cached stub, wherein the component was empirically determined to be similar but not identical across multiple requests for the webpage, wherein the component was empirically determined as having the same number and the same types of attributes across multiple requests for the webpage but having at least one attribute with a value that changes across multiple requests for the webpage; and replacing the at least one attribute of the component included in the cached stub by a placeholder; and activating a script that intercepts any access to the placeholder, wherein the script causes a reloading of the webpage in response to a determination that the placeholder has been accessed. 